package com.zx.znav.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zx.znav.bean.Tag;
import com.zx.znav.service.TagService;
import com.zx.znav.mapper.TagMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lenovo
* @description 针对表【t_tag】的数据库操作Service实现
* @createDate 2023-07-21 07:42:41
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag>
    implements TagService{
    @Override
    public List<Tag> listTags() {
        LambdaQueryWrapper<Tag> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Tag::getLinkCnt).orderByAsc(Tag::getName);
        return list(wrapper);
    }

    @Override
    public List<Tag> search(String name) {
        LambdaQueryWrapper<Tag> wrapper = new LambdaQueryWrapper<>();
        //根据name模糊查询
        wrapper.like(name != null, Tag::getName, name);
        //排序
        wrapper.orderByDesc(Tag::getLinkCnt).orderByAsc(Tag::getName);
        return list(wrapper);
    }

    @Override
    public List<Tag> listTopTag(int size) {
        LambdaQueryWrapper<Tag> wrapper = new LambdaQueryWrapper<>();
        //排序
        wrapper.orderByDesc(Tag::getLinkCnt).orderByAsc(Tag::getName);
        wrapper.last("limit " +size);
        return list(wrapper);
    }
}




